/**
 *  Module Name: 	SecrecySystem.cpp
 *  
 *  Module implements a set of APIs used to protect and unprotect messages. 
 *  
 *  This secrecy system is based on  Advanced Encryption Standard (AES).
 * 
 * 
 * @author Ravi Mohandas, Mar 06 2011
 */


#include "stdafx.h"
#include <stdio.h>

#include "SecrecySystem.h"
#include "AESUtils.h"
#include "AESDefs.h"
#include "SecrecyAES.h"


	/**
	 *	Module scoped variables 
	 * 
	 */

	static SecrecySystem	_secrecySys;

SECRECY_SYSTEM_API 
int Init ()
{
	SecrecyLevel	secrecy_level;
	KeySize			keysize;
	byte**			keyRef = NULL;
	
	keyRef			= get_keyRef(&_secrecySys);

	if (keyRef == NULL){
		return E_INVALID_STATE;
	}

	secrecy_level	= get_secrecyLevel(&_secrecySys);

	if ( secrecy_level == Strong)
	{
		keysize = System_key128;

		InitAES (*keyRef, keysize);
	}
	else if  ( secrecy_level == Very_Strong)
	{
		keysize = System_key192;
		InitAES (*keyRef, keysize);
	}
	else if  ( secrecy_level == Maximum)
	{
		keysize = System_key256;
		InitAES (*keyRef, keysize);
	}

	return 0;
}

SECRECY_SYSTEM_API 
int  Protect (const byte in[], const byte out[], int length)
{

	return 0;
}

SECRECY_SYSTEM_API 
int  UnProtect (const byte in[], const byte out[], int length)
{
	
	return 0;
}


/**
 * Configure the strength of the secrecy operations performed on a message. 
 * 
 */


SECRECY_SYSTEM_API  
int ConfigureSecrecyLevel (SecrecyLevel secrecy_level)
{	
	set_secrecyLevel (&_secrecySys, secrecy_level);

	return 0;
}

SECRECY_SYSTEM_API 
int ConfigureKey (byte keyBytes [], int keyLength)
{
	set_keyRef (&_secrecySys, keyBytes, keyLength);

	return 0;
}

SECRECY_SYSTEM_API int Close(void)
{	
	printf ("Close called\n");
	return 0;
}
